package cn.itsource.hrm.web.controller;

import cn.itsource.hrm.util.AjaxResult;
import cn.itsource.hrm.util.RedisUtils;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

@RestController
@RequestMapping("/redis")
public class RedisController {
    //添加设置数据
    @PostMapping("/set")
    public AjaxResult set(@RequestParam("key") String key, @RequestParam("value") String value){
        RedisUtils.INSTANCE.set(key,value);
        return AjaxResult.me();
    }
    @PostMapping("/setex")
    public AjaxResult setex(@RequestParam("key") String key,@RequestParam("seconds") int seconds, @RequestParam("value") String value){
        RedisUtils.INSTANCE.setex(key,seconds,value);
        return AjaxResult.me();
    }

    //获取key所对应的value
    @GetMapping("/get/{key}")
    public AjaxResult get(@PathVariable("key") String key){
        //获取key值对应的value
        String result = RedisUtils.INSTANCE.get(key);
        //将结果值添加到AjaxResult结果对象
        return AjaxResult.me().setResultObj(result);
    }
}
